package leetcode.math;

/**
 * https://leetcode-cn.com/problems/reverse-integer/
 *
 * @author mazouri
 * @create 2021-09-30 21:17
 */
public class _7_reverse {
    public int reverse(int x) {
        StringBuilder sb = new StringBuilder();
        int isPositive = 1;
        if (x < 0) {
            x = -x;
            isPositive = -1;
        }

        try {
            return Integer.parseInt(sb.append(x).reverse().toString()) * isPositive;
        } catch (NumberFormatException e) {
            return 0;
        }
    }

    public static void main(String[] args) {
        System.out.println(new _7_reverse().reverse(-2147483648));
    }
}
